package com.mycompany.app.hr.security.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import com.mycompany.app.common.audit.modification.model.AuditEmbeddedObject;

@SuppressWarnings("unchecked")
@Entity
@Table(name = "s_permission")
public class SystemPermission {

    @Id
    @Column(name = "permission_id")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(name = "permission_name")
    private String permissionName;

    private String description;

    @Column(name = "operation_value")
    private String operationValue;

    @Column(name = "is_active")
    private Boolean isActive;
    
    @ManyToMany(mappedBy="permissions",cascade=CascadeType.PERSIST,fetch=FetchType.LAZY)
    private Set<SystemRole> roles=new HashSet<SystemRole>(0);
    
    @ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
    @JoinTable(name = "s_permission_resource", joinColumns = { @JoinColumn(name = "permission_id") }, inverseJoinColumns = { @JoinColumn(name = "resource_id") })
    private Set<SystemResource> resources=new HashSet<SystemResource>(0);

    @Embedded
    private AuditEmbeddedObject auditEmbeddedObject = new AuditEmbeddedObject();

    // ===================================
    @Override
    public String toString() {

        return ToStringBuilder.reflectionToString(this,
                ToStringStyle.SHORT_PREFIX_STYLE);
    }

    // ===================================

    public Long getId() {

        return id;
    }

    public void setId(Long id) {

        this.id = id;
    }

    public String getPermissionName() {

        return permissionName;
    }

    public void setPermissionName(String permissionName) {

        this.permissionName = permissionName;
    }

    public String getDescription() {

        return description;
    }

    public void setDescription(String description) {

        this.description = description;
    }

    public String getOperationValue() {

        return operationValue;
    }

    public void setOperationValue(String operationValue) {

        this.operationValue = operationValue;
    }

    public Boolean getIsActive() {

        return isActive;
    }

    public void setIsActive(Boolean isActive) {

        this.isActive = isActive;
    }

    public AuditEmbeddedObject getAuditEmbeddedObject() {

        return auditEmbeddedObject;
    }

    public void setAuditEmbeddedObject(AuditEmbeddedObject auditEmbeddedObject) {

        this.auditEmbeddedObject = auditEmbeddedObject;
    }

    public Set<SystemRole> getRoles() {
    
        return roles;
    }

    public void setRoles(Set<SystemRole> roles) {
    
        this.roles = roles;
    }

    public Set<SystemResource> getResources() {
    
        return resources;
    }

    public void setResources(Set<SystemResource> resources) {
    
        this.resources = resources;
    }
    
    

}
